package com.lzh.eventdemo.service;

import com.lzh.eventdemo.event.UserRegisterEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

/**
 * @Description:
 * @Author: LiuZiHao
 * @Date: 2022/8/30 10:22
 */
@Service
public class UserService implements ApplicationEventPublisherAware {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    public void register(String username) {
        //1.执行注册逻辑
        logger.info("[register][执行用户({})的注册逻辑]", username);
        //2发布
        applicationEventPublisher.publishEvent(new UserRegisterEvent(this, username));

    }
}
